#include <iostream>
#include <string>
#include <jsoncpp/json/json.h>
using namespace std;

// 简单工厂模式

// 抽象产品类:所有子类对象的共同父类,负责描述所有派生类所共有的公共接口                       

/*
class Operation
{
public:
    double m_leftValue;
    double m_rightValue;
    virtual double GetResult() = 0;
};

// 具体产品类
class AddOperation : public Operation
{
    double GetResult() override
    {
        return m_leftValue + m_rightValue;
    }
};

// 具体产品类
class SubOperation : public Operation
{
    double GetResult() override
    {
        return m_leftValue - m_rightValue;
    }
};

// 工厂类OperatorFactory专门负责创建具体产品类(AddOperation/SubOperation)的实例
// 可以根据不同的参数返回不同类的实例

class OperatorFactory
{
public:
    // 创建产品对象,返回抽象类产品类型,方便实现多态调用
    static Operation *CreateOperation(char c)
    {
        switch (c)
        {
        case '+':
            return new AddOperation;
            break;
        case '-':
            return new SubOperation;
            break;
        default:
            return nullptr;
        }
    }
};

int main()
{
    Operation *add = OperatorFactory::CreateOperation('-');
    add->m_leftValue = 10;
    add->m_rightValue = 20;
    cout << add->GetResult() << endl;
    return 0;
}
*/

/*
int main()
{
    Json::Value root;
    root["name"]="wangzheng";
    root["age"]=18;

    Json::FastWriter writer;
    string str=writer.write(root);
    cout<<str<<endl;
    
    return 0;
}
*/